package com.cust.cow.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.cust.cow.common.CowMatingLog;
import com.cust.cow.common.Result;
import com.cust.cow.mapper.CowCattleMapper;
import com.cust.cow.pojo.breed;
import com.cust.cow.pojo.cattle;
import com.cust.cow.pojo.cowCattle;
import com.cust.cow.service.CattleService;
import com.cust.cow.service.CowCattleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CowCattleServiceImpl implements CowCattleService {
    @Autowired
    private CowCattleMapper cowCattleMapper;

    @Override
    public List<cowCattle> findCowCattleAll() {
        return cowCattleMapper.findCowCattleAll();
    }

    @Override
    public Result insertCowCattle(cowCattle cowCattle) {
        cowCattleMapper.insertCowCattle(cowCattle);
        return new Result(200, "插入成功");
    }

    @Override
    public Result deleteCowCattle(Integer cattleId) {
        cowCattleMapper.deleteCowCattle(cattleId);
        return new Result(200, "删除成功");
    }

    @Override
    public CowMatingLog findCowCattleById(Integer cattleId) {
        return cowCattleMapper.findCowCattleById(cattleId);
    }

    @Override
    public List<CowMatingLog> findCowCattleMatingLogAll() {
        return cowCattleMapper.findCowCattleMatingLogAll();
    }

    @Override
    public Result updateCowCattleProductionStatus(cowCattle cowCattle) {
        UpdateWrapper<cowCattle> wrapper = new UpdateWrapper<>();
        wrapper.eq("cattle_id", cowCattle.getCattleId()).set("production_status", cowCattle.getProductionStatus());

        int result = cowCattleMapper.update(cowCattle,wrapper);
        if (result <= 0) {
            return new Result(100, "更新失败");
        }
        return new Result(200, "更新成功");
    }
}
